//
//  MYlobalMacro.h
//  JQLive
//
//  Created by Bruce on 2019/11/28.
//  Copyright © 2019 mlqk. All rights reserved.
//

#ifndef MYlobalMacro_h
#define MYlobalMacro_h
//-------------------打印日志-------------------------

//DEBUG模式下打印日志,当前行

#ifdef DEBUG
#define ISDEBUG YES

//#define DLog(fmt,...)NSLog((@"\n/******************\n%s[Line %d]" fmt),__PRETTY_FUNCTION__,__LINE__,##__VA_ARGS__);
#define DLog( s, ... ) printf("\n/*****************\nclass: <%p %s:(%d) > method: %s \n%s\n******************/\n", self, [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(s), ##__VA_ARGS__] UTF8String] )

#else
#define ISDEBUG NO

//#define DLog(...)
#define DLog( s, ... ) printf("\n/*****************\nclass: <%p %s:(%d) > method: %s \n%s\n******************/\n", self, [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(s), ##__VA_ARGS__] UTF8String] )

#endif

//DEBUG 模式下打印日志,当前行 并弹出一个警告
#ifdef DEBUG
 #  define ULog(fmt, ...)  { UIAlertView *alert = ［UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; }

 #else
 #  define ULog(...)
 #endif
//数据为空时赋值为“”
#define STRING_OR_EMPTY(A) ({ typeof(A) __a = (A); __a ? __a : @""; })
//字符串是否为空
#define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )
//数组是否为空
#define kArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)
//字典是否为空
#define kDictIsEmpty(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0)
//是否是空对象
#define kObjectIsEmpty(_object) (_object == nil \
 || [_object isKindOfClass:[NSNull class]] \
 || ([_object respondsToSelector:@selector(length)] && [(NSData *)_object length] == 0) \
 || ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] == 0))
#pragma mark -设备相关
//判断是否是ipad
#define isPad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
//判断iPhone5系列
#define kiPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) && !isPad : NO)
//判断iPhone6 6s 7系列
#define kiPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) && !isPad : NO)
//判断iPhone6p 6sp 7p系列
#define kiPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) && !isPad : NO)
//判断iPhoneX，Xs（iPhoneX，iPhoneXs），iPhone 11 Pro
#define IS_IPHONE_X ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !isPad : NO)
//判断iPhoneXr，iPhone 11
#define IS_IPHONE_Xr ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) && !isPad : NO)
//判断iPhoneXsMax，iPhone 11 Pro Max
#define IS_IPHONE_Xs_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size)&& !isPad : NO)

//判断iPhoneX所有系列
#define IS_PhoneXAll (IS_IPHONE_X || IS_IPHONE_Xr || IS_IPHONE_Xs_Max)

//判断是否为刘海屏
#define INTERFACE_IS_IPHONEX \
({BOOL isPhoneX = NO;\
if (@available(iOS 11.0, *)) {\
isPhoneX = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0;\
}\
(isPhoneX);})

// 适配iPhone X 状态栏高度
#define  MY_StatusBarHeight      (IS_PhoneXAll ? 44.f : 20.f)
// 适配iPhone X Tabbar高度
#define  MY_TabbarHeight   49.f
// 适配iPhone X 有Tabbar安全距离
#define  MY_TabbarSafeBottomMargin   (IS_PhoneXAll ? (49.f+34.f) : 49.f)
// 适配iPhone X 导航栏高度
#define  MY_NavHeight  44.f

#define  MY_TopSafeMargin   (IS_PhoneXAll ? (44+44.f) : (44+20.f))
#define  MY_BottomSafeMargin   (IS_PhoneXAll ? 34.f : 0.f)

#define  MY_NavTopHeight   (IS_PhoneXAll ? (44+44.f) : (44+20.f))
#define  MY_BottomTabbarHeight   (IS_PhoneXAll ? 34.f : 0.f)



//获取屏幕宽度与高度 ( " \ ":连接行标志，连接上下两行 )
#define kScreenWidth \
([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.width)

#define kScreenHeight \
([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.height)

#define kScreenSize \
([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? CGSizeMake([UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale,[UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale) : [UIScreen mainScreen].bounds.size)
/**宽度比例*/
#define MY_ScaleWidth(__VA_ARGS__)  (kScreenWidth/375)*(__VA_ARGS__)
/**高度比例*/
#define MY_ScaleHeight(__VA_ARGS__)  (kScreenHeight/812)*(__VA_ARGS__)
//一些常用的缩写
#define kApplication        [UIApplication sharedApplication]

#define kKeyWindow          [UIApplication sharedApplication].keyWindow

#define kAppDelegate        [UIApplication sharedApplication].delegate

#define kUserDefaults      [NSUserDefaults standardUserDefaults]

#define kNotificationCenter [NSNotificationCenter defaultCenter]

//APP版本号
#define kAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

//系统版本号
#define kSystemVersion [[UIDevice currentDevice] systemVersion]

//获取当前语言
#define kCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
#define LanguageIsEnglish ([kCurrentLanguage isEqualToString:@"en-US"] || [kCurrentLanguage isEqualToString:@"en-CA"] || [kCurrentLanguage isEqualToString:@"en-GB"] || [kCurrentLanguage isEqualToString:@"en-CN"] || [kCurrentLanguage isEqualToString:@"en"])

//判断是否为iPad
#define kISiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

//获取沙盒Document路径
#define kDocumentPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]

//获取沙盒temp路径
#define kTempPath NSTemporaryDirectory()

//获取沙盒Cache路径
#define kCachePath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

//判断是真机还是模拟器
#if TARGET_OS_IPHONE
//真机
#endif
#if TARGET_IPHONE_SIMULATOR
//模拟器
#endif

//颜色
#define kRGBColor(r, g, b)    [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]

#define kRGBAColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(r)/255.0 blue:(r)/255.0 alpha:a]

#define kRandomColor      kRGBColor(arc4random_uniform(256),arc4random_uniform(256),arc4random_uniform(256))        //随机色生成


#define kColorAWithHex(rgbValue, a) \
[UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16)) / 255.0 \
green:((float)((rgbValue & 0xFF00) >> 8)) / 255.0 \
blue:((float)(rgbValue & 0xFF)) / 255.0 alpha:a]

#define kColorWithHex(rgbValue) \
[UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16)) / 255.0 \
green:((float)((rgbValue & 0xFF00) >> 8)) / 255.0 \
blue:((float)(rgbValue & 0xFF)) / 255.0 alpha:1.0]

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]


#define MYColor9 UIColorFromRGB(0x999999)
#define MYColor3 UIColorFromRGB(0x333333)
#define MYColor6 UIColorFromRGB(0x666666)
#define MYColor0 UIColorFromRGB(0x000000)
#define MYColor1 UIColorFromRGB(0x111111)
#define MYColorYellow UIColorFromRGB(0xE06921)
#define MYColorTitleSelected UIColorFromRGB(0xFFD58B)

#define MYHome_backgroundColor UIColorFromRGB(0x000097)

#define RGBACOLOR(rgbValue) kColorWithHex(rgbValue)
//弱引用/强引用
#define kWeakSelf(type)  __weak typeof(type) weak##type = type;

#define kStrongSelf(type) __strong typeof(type) type = weak##type;

//获取一段时间间隔
#define kStartTime CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();

#define kEndTime  NSLog(@"Time: %f", CFAbsoluteTimeGetCurrent() - start);
#pragma mark -View相关
//获取视图子视图，无子视图则返回自身
#define getLastView(lastView)  lastView.subviews.lastObject == nil?lastView:lastView.subviews.lastObject
//View圆角和加边框
#define ViewBorderRadius(View,Radius,Width,Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]

// View圆角
#define ViewRadius(View,Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]


//解决这个方法提醒
#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)

#define safeString(string) (string ? string : @"")
#define safeArray(array) (array ? array : [NSNull null])
#define MY_OBJ_NOT_NULL(obj) (obj && ![obj isEqual:[NSNull null]])
#define MY_WEAK __weak typeof(self) weakSelf = self
#define MY_STRONG __strong typeof(weakSelf) strongSelf = weakSelf

#define DefaultAvatarImage UIImageMake(@"ic_loading_bg") ////DefaultAvatarImage
#define DefaultGroupAvatarImage UIImageMake(@"ic_loading_bg")




#endif /* MYlobalMacro_h */
